package org.streets.wicket.internal;

import org.apache.tapestry5.ioc.internal.util.CollectionFactory;
import org.apache.tapestry5.ioc.internal.util.InternalUtils;
import org.apache.tapestry5.ioc.services.SymbolProvider;

import javax.servlet.ServletContext;
import java.util.Map;

/**
 * A wrapper around {@link ServletContext} that makes init-parameters accessible as symbols.
 */
public class ServletContextSymbolProvider implements SymbolProvider
{
    private final Map<String, String> properties = CollectionFactory.newCaseInsensitiveMap();

    public ServletContextSymbolProvider(ServletContext context)
    {
        for (String name : InternalUtils.toList(context.getInitParameterNames()))
        {
            properties.put(name, context.getInitParameter(name));
        }
    }

    public String valueForSymbol(String symbolName)
    {
        return properties.get(symbolName);
    }

}
